(function () { // Anonymous function to keep global namespace clean.
	var basePath  = "";
	for (var i = 0, scripts = document.getElementsByTagName("script"); i < scripts.length; i++)
        if (scripts[i].src.match("all_scripts.js")) { 
            basePath = scripts[i].src.replace("all_scripts.js", "");
            break;
        }
        
	document.write('<'+'link href="'+basePath+'tablecloth/tablecloth/tablecloth.css" rel="stylesheet" type="text/css" />');
	document.write('<'+'script type="text/javascript" src="'+basePath+'tablecloth/tablecloth/tablecloth.js"></'+'script>');
	
	document.write('<'+'script type="text/javascript" src="'+basePath+'../js/jquery-1.4.2.min.js"></'+'script>');
	document.write('<'+'script type="text/javascript" src="'+basePath+'../js/template.js"></'+'script>');
    
}) ();

/*标签设置（系统用）*/
  function setTab(name,cursel,n){  //,n
 for(i=1;i<=n;i++){  
  var menu=document.getElementById(name+i);  
  var con=document.getElementById("con_"+name+"_"+i);  
  menu.className=i==cursel?"hover":"";  
  con.style.display=i==cursel?"block":"none";  
  }  
 } 
 /*元素事件监听驱动*/
      // Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling) {
	bubbling = bubbling || false;
	if (window.addEventListener) { // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if (window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else
		return false;
}
/*checkbox 统一判断方式*/
 function getElementsByType(sTypeValue,oBox,oboolean) {
	var b= (oboolean!=false)? true:false;
	this.d= oBox || document;
	var children = this.d.getElementsByTagName("*") || document.all;
	var elements = new Array();
		for (var ii = 0; ii < children.length; ii++) {
			if (children[ii].type == sTypeValue) {
				   elements.push(children[ii]);
				if(sTypeValue=="checkbox" && b==true){//对checkbox类型初始化
				  (children[ii].value=="Y")?children[ii].checked = true:children[ii].checked = false;
		          addListener(children[ii],"click",cbonclick);
				}
			}
		}
		return elements;
	}
	/*checkbox onclick*/
	function cbonclick(){
	  (this.checked)?this.value = "Y" : this.value = "N";
	  //alert(this.value);
	}
	
	
function getElementsByType_1_0(sTypeValue,oBox,oboolean) {
	var b= (oboolean!=false)? true:false;
	this.d= oBox || document;
	var children = this.d.getElementsByTagName("*") || document.all;
	var elements = new Array();
		for (var ii = 0; ii < children.length; ii++) {
			if (children[ii].type == sTypeValue) {
				   elements.push(children[ii]);
				if(sTypeValue=="checkbox" && b==true){//对checkbox类型初始化
				  (children[ii].value=="1")?children[ii].checked = true:children[ii].checked = false;
		          addListener(children[ii],"click",cbonclick_1_0);
				}
			}
		}
		return elements;
	}
	/*checkbox onclick*/
	function cbonclick_1_0(){
	  (this.checked)?this.value = "1" : this.value = "0";
	  //alert(this.value);
	}
	
/*取得id相同的对象集合*/
function HTJS_docGetid() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
/*取得TagName相同的元素结合*/
$Tag = function (s,o){
this.d=o || document;
return this.d.getElementsByTagName(s);
};

/*回车与tab键等同*/
var ie =navigator.appName=="Microsoft Internet Explorer"?true:false; 

function keyDown(e) {
	if (!ie) {
		var nkey = e.which;
		var iekey = '现在是ns浏览器';
		var realkey = String.fromCharCode(e.which);
		if (nkey == 13) {
			// var newEvent = document.createEvent("KeyEvents");
			//newEvent.initKeyEvent("keypress", true, true, document.defaultView, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0,9);
			//e.preventDefault();
			//e.target.dispatchEvent (newEvent);
			//alert(e.target.tagName);
        if (e.target.tagName != "TEXTAREA"){
			var childrens_tmp = document.getElementsByTagName("*")
					|| document.all;
			var childrens = new Array();
			for (i = 0; i < childrens_tmp.length; i++) {
				if ((childrens_tmp[i].tagName == "INPUT" || childrens_tmp[i].tagName == "SELECT" || childrens_tmp[i].tagName == "TEXTAREA")	&& (childrens_tmp[i].type != "hidden") && (childrens_tmp[i].style.display != "none"))
				{
					childrens.push(childrens_tmp[i]);
				}
			}//rof    
			for (i = 0; i < childrens.length; i++) {
				if (childrens[i].id == e.target.id) {
					childrens[i + 1].focus();
					//alert(childrens[i + 1].id);
					break;
				}
			}//rof
		 }
		}
	}
	if (ie) {
		var iekey = event.keyCode;
		var nkey = '现在是ie浏览器';
		var realkey = String.fromCharCode(event.keyCode);
		if (event.keyCode == 32) {
			realkey = '\' 空格\''
		}
		if (event.keyCode == 13) {
			realkey = '\' 回车\'';
			// event.srcElement.type!='submit' && event.srcElement.type!='reset'
			if (event.srcElement.type != 'button'
					&& event.srcElement.type != 'textarea'
					&& event.srcElement.type != '')
				event.keyCode = 9;
		}
		if (event.keyCode == 27) {
			realkey = '\' Esc\''
		}
		if (event.keyCode == 16) {
			realkey = '\' Shift\''
		}
		if (event.keyCode == 17) {
			realkey = '\' Ctrl\''
		}
		if (event.keyCode == 18) {
			realkey = '\' Alt\''
		}
	}
	//alert('ns浏览器中键值:'+nkey+'\n'+'ie浏览器中键值:'+iekey+'\n'+'实际键为'+realkey); 
}
//document.onkeydown = keyDown;//设置全局按键事件

/**
 * 图片上传函数
 * @return {Boolean}
 */
	function ajaxFileUpload(imageobj,cbhidden,callback)
	{
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).show();
		});

		$.ajaxFileUpload
		(
			{
				url:pt.get("contextPath")+'/fileuploadservlet',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							if(imageobj!=null && imageobj!=undefined)
							imageobj.src = "/web_img/"+data.fileurl;
							if(cbhidden!=null && cbhidden!=undefined) 
							cbhidden.value = data.fileurl;
							alert(data.msg);
							if(callback != undefined)
							callback(data,status);
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}
	
	
	/**
 * 图片上传函数
 * @return {Boolean}
 */
	function ajaxFilesUpload(imageobj,elid,cbhidden)
	{
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).show();
		});

		$.ajaxFileUpload
		(
			{
				url:pt.get("contextPath")+'/fileuploadservlet',
				secureuri:false,
				fileElementId:elid,
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							if(imageobj!=null && imageobj!=undefined)
							imageobj.src = "/web_img/"+data.fileurl;
							if(cbhidden!=null && cbhidden!=undefined) {
								if(cbhidden.value==""){
									cbhidden.value = data.fileurl;
									
								}
								else{
									cbhidden.value=cbhidden.value+","+data.fileurl;
								}
							}
							alert(data.msg);
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}
	

